

a = [
("01-funcional-clase1.pdf", 14),
("02-funcional-2da.pdf", 26),
("03-clambda1.pdf", 40),
("04-clambda2.pdf", 32),
("05-clase-inferencia.pdf", 28),
("06-prolog.pdf", 25),
("07-logica.pdf", 34),
("08-resolucion1.pdf", 35),
("09-resolucion2.pdf", 19),
("10-subtipado.pdf", 16),
]

for (file_name, num) in a:
    #~ file_name= "archivo.pdf"
    #~ num =33
    res = 'pdfjam ' + file_name + " '"
    i=0
    frente = []
    reverso = []
    count = 0
    bool_prim = True
    for j in range(1, num+1):
        if i == 16:
            for k in frente:
                res += (str(k) + ",")
            for k in reverso:
                res += (str(k) + ",")

            i = 0
            frente = []
            reverso = []
            
        if count == 4: 
            bool_prim = not bool_prim
            count = 0
            
        if bool_prim:
            frente.append(j)
        else:
            reverso.append(j)
            
        i += 1
        count += 1
        

    for k in frente:
        res += (str(k) + ",")
    for k in range(0, 8-len(frente)):
        res += ("{},")

    for k in reverso:
        res += (str(k) + ",")    
    for k in range(0, 8-len(reverso)):
        res += ("{},")

    res = res[:-1]
    res += ("' --landscape --outfile " + str(file_name) + "out.pdf ")
    print res
    #pdfjam file1.pdf '{},2-' file2.pdf '10,3-6' --outfile ../myNewFile.pdf
    
for (file_name, num) in a:
    print "pdfnup --nup 2x4 " + str(file_name) + "out.pdf  --no-landscape  --outfile "  + str(file_name) + "final.pdf "
